home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / zoom_24.pro < prev    next >
Text File  |  1997-07-08  |  7KB  |  261 lines

  1. ; $Id: zoom_24.pro,v 1.4 1996/12/17 01:21:43 ali Exp $
  2.  
  3. pro zoom_24, xsize=xs, ysize=ys, fact=fact, right=right
  4. ;+
  5. ; NAME:    
  6. ;    ZOOM_24
  7. ;
  8. ; PURPOSE:
  9. ;    Display part of a 24-bit color image from the current window
  10. ;    expanded in another window.  (This procedure was modified from the 
  11. ;    8-bit procedure ZOOM).
  12. ;
  13. ;    The cursor and left mouse button are used to mark the center of the 
  14. ;    zoom.  The cursor can be moved into the zoom window to determine the 
  15. ;    coordinates (in the original image) and color values of individual 
  16. ;    pixels.  In the zoom window, the right mouse button returns you to the
  17. ;    mode for selecting a new zoom window or magnification factor
  18. ;    from the original image.  The center mouse button is used in the 
  19. ;    original picture window to bring up the magnification-factor 
  20. ;    selector.  The mouse button erases the zoom window and pixel window
  21. ;    and exits.
  22. ;
  23. ; CATEGORY:
  24. ;    Image display.
  25. ;
  26. ; CALLING SEQUENCE:
  27. ;    ZOOM_24 [, XSIZE = Xsize, YSIZE = Ysize, FACT = Fact, /RIGHT] 
  28. ;
  29. ; INPUTS:
  30. ;    All input parameters are passed as keywords.
  31. ;
  32. ; KEYWORDS:
  33. ;    XSIZE:    The X size of the zoom window.  The default is 512.
  34. ;
  35. ;    YSIZE:    The Y size of zoom window.  The default is 512.
  36. ;
  37. ;    FACT:    The zoom enlargement factor.  The default is 4.
  38. ;
  39. ;    RIGHT:    Position keyword (0 = left screen, 1 = right screen).
  40. ;
  41. ; OUTPUTS:
  42. ;    No explicit outputs. Two new windows are created, and both
  43. ;    are destroyed when the procedure is exited.
  44. ;
  45. ; COMMON BLOCKS:
  46. ;    None.
  47. ;
  48. ; SIDE EFFECTS:
  49. ;    Two windows are created/destroyed.  An auxiliary image
  50. ;    array is created.
  51. ;
  52. ; RESTRICTIONS:
  53. ;    ZOOM_24 only works with 24-bit color systems.
  54. ;
  55. ; PROCEDURE:
  56. ;    Straightforward.
  57. ;
  58. ; MODIFICATION HISTORY:
  59. ;    Original: 9-March-1990    W. T. Vetterling
  60. ;-
  61.  
  62. if n_elements(xs) le 0 then xs=512    ; Default x-size
  63. if n_elements(ys) le 0 then ys=512    ; Default y-size
  64. if n_elements(fact) le 0 then fact=4    ; Default magnification
  65.  
  66. waitflg=3            ; Wait for mouse clicks
  67. ifact = fact               
  68. orig_w = !d.window        ; Save original window number
  69. orig_ysiz=!d.y_vsize        ; Save original window y-size
  70. xs = xs < !d.x_vsize        ; For small originals, don't
  71. ys = ys < !d.y_vsize          ;   make zoom window too large
  72. tvcrs,1                ; Enable cursor
  73. ierase = 0            ; Erase zoom window flag
  74.  
  75. lm=50                ; Left margin, pixel window
  76. bm=50                           ; Bottom margin, pixel window
  77. box=60                ; Size of color box
  78. barw=20                ; Width of color bars
  79. barl=128            ; Maximum length of bars
  80. bars=20                ; Separation of color bars
  81.  
  82. lbar=lm+box+30            ; Left end of color bars
  83. rbar=lbar+barl            ; Right end of color bars
  84.  
  85. rbox=lm+box            ; Right side of box
  86. tbox=bm+box            ; Top of box
  87.  
  88. rtext=lm+300            ; Right end of text
  89. btext=bm+120            ; Bottom of text
  90. ttext=bm+175            ; Top of text
  91.  
  92. bar1b=bm            ; Bar 1 bottom
  93. bar1t=bm+barw                   ; Bar 1 top
  94. bar2b=bar1t+bars                ; Bar 2 bottom
  95. bar2t=bar2b+barw                ; Bar 2 top
  96. bar3b=bar2t+bars                ; Bar 3 bottom
  97. bar3t=bar3b+barw                ; Bar 3 top
  98.  
  99. red=255L            ; Colors for graphics
  100. green=red*256                   ;   in pixel window
  101. blue=green*256
  102. black=0
  103. white=red+green+blue
  104.  
  105. if keyword_set(right) then xp=!d.x_size+20 else xp=0
  106. ; Position expansion windows to left or right of original
  107.  
  108. window,xpos=xp,ypos=0,xsize=xs,ysize=ys,title='Zoomed Image',/free
  109. zoom_w = !d.window
  110.  
  111. window,xpos=xp,ypos=ys+30,xsize=rbar+20,ysize=ttext+40,title='Pixel Values',/free
  112. pixel_w = !d.window
  113.  
  114. !p.color=white          ; Post instructions
  115. xyouts,lm,bm+125,'Make Selection From Original:',/dev
  116. xyouts,lm,bm+100,'   Left Button Selects Region',/dev
  117. xyouts,lm,bm+75,'   Center Button Selects Size',/dev
  118. xyouts,lm,bm+50,'   Right Button Exits',/dev
  119.  
  120. wset,orig_w
  121.  
  122. again:
  123.     CURSOR,x,y,waitflg,/dev    ;Wait for mousie
  124.  
  125.     case !err of
  126.  
  127. 4:    goto, done        ; Right-hand mouse button quits
  128.  
  129. 2:    if !d.name eq 'SUN' or !d.name eq 'X' then begin
  130.                 ; Center mouse button brings up
  131.                 ;   scale for choosing magnification
  132.         s  = ['New Zoom Factor:',strtrim(indgen(19)+2,2)]
  133.         ifact = wmenu(s,init=ifact-1,title=0)+1
  134.                 IF (!Version.Os NE 'MacOS') THEN $
  135.                         tvcrs,x,y,/dev $        ;Restore cursor
  136.                 ELSE tvcrs,1
  137.         ierase = 1
  138.     endif else begin
  139.         Read,'Current factor is',ifact+0,'.  Enter new factor: ',ifact
  140.         if ifact le 0 then begin
  141.             ifact = 4
  142.             print,'Illegal Zoom factor.'
  143.         endif
  144.         ierase = 1    ; Clean out previous display
  145.     endelse
  146.  
  147. else:    begin                     ; Left-hand mouse button gives 
  148.                         ;   expanded image
  149.         nx = xs/ifact            ; Size of new image
  150.         ny = ys/ifact
  151.  
  152.         x0 = 0 > (x-nx/2)         ; Make sure we don't crop
  153.         y0 = 0 > (y-ny/2)         ;   image on left or bottom
  154.         x0 = x0 < (!d.x_vsize - nx)     ; Make sure we don't crop
  155.         y0 = y0 < (!d.y_vsize - ny)     ;   image on the right or top
  156.  
  157.         a = tvrd(x0,y0,nx,ny,true=3)    ; Read image, pixel interleaved
  158.  
  159.         wset,pixel_w            ; Erase pixel window
  160.         erase
  161.  
  162.         wset,zoom_w            ; Go to zoom window
  163.         if ierase then erase        ; Erase it?
  164.         ierase = 0
  165.  
  166.         xss = nx * ifact        ; Make integer rebin factors
  167.         yss = ny * ifact
  168.  
  169.         b=rebin(a,xss,yss,3,/sample)    ; Rebin to correct size
  170.                         ;   using pixel replication
  171.                         ;   if necessary
  172.         tv,b,0,0,true=3                  ; Show the magnified image
  173.     
  174. loop:
  175.         wset,zoom_w            ; Go to the zoomed window
  176.         cursor,x,y,2,/dev        ; Continuously sample the
  177.                         ;   mouse coordinates
  178.         if (!err eq 4) then goto,another
  179.                         ; If right-hand button is
  180.                         ;   pushed, get another sample
  181.                         ;   from the original
  182.         wset,pixel_w            ; Otherwise, go to pixel
  183.                         ;   window
  184.  
  185.         xx=string(format='(i3)',(x0+x/ifact))    ; Coordinate text
  186.              yy=string(format='(i3)',(y0+y/ifact))
  187.  
  188.         rstr=string(format='(i3)',b[x,y,0])
  189.                         ; Color text
  190.         gstr=string(format='(i3)',b[x,y,1])
  191.         bstr=string(format='(i3)',b[x,y,2])
  192.  
  193.         bar1=lbar+b[x,y,0]/2
  194.         bar2=lbar+b[x,y,1]/2
  195.         bar3=lbar+b[x,y,2]/2
  196.  
  197.         !p.color=black            ; Cover old text
  198.         polyfill,[lm,rtext,rtext,lm],[btext,btext,ttext,ttext],/dev
  199.         ; Note: This is faster than erase
  200.  
  201.                !p.color=white            ; Set color to white
  202.         xyouts,lm,bm+155,'Position: ('+xx+','+yy+')',/dev
  203.         xyouts,lm,bm+130,'Value:    ('+rstr+','+gstr+','+bstr+')',/dev
  204.  
  205.         !p.color=black            ; Cover old color bars
  206.         polyfill,[lbar,rbar,rbar,lbar],[bar1b,bar1b,bar3t,bar3t],/dev
  207.  
  208.         !p.color=red            ; Red bar
  209.         polyfill, [lbar,bar1,bar1,lbar],[bar3b,bar3b,bar3t,bar3t],/dev
  210.  
  211.         !p.color=green            ; Green bar
  212.         polyfill, [lbar,bar2,bar2,lbar],[bar2b,bar2b,bar2t,bar2t],/dev
  213.  
  214.         !p.color=blue            ; Blue bar
  215.         polyfill, [lbar,bar3,bar3,lbar],[bar1b,bar1b,bar1t,bar1t],/dev
  216.  
  217.         !p.color=b[x,y,0]+256.0*(b[x,y,1]+256.0*b[x,y,2])
  218.                     ;Box showing pixel color
  219.         polyfill, [lm,rbox,rbox,lm],[bm,bm,tbox,tbox],/dev
  220.     
  221.         goto,loop        ; Get another pixel value
  222.  
  223. another:                ; Get another section of original
  224.                     ;   image
  225.  
  226.         wset,pixel_w            ; Erase pixel window
  227.         erase
  228.  
  229.         !p.color=white          ; ... and give instructions
  230.         xyouts,lm,bm+125,'Make Selection From Original:',/dev
  231.         xyouts,lm,bm+100,'   Left Button Selects Region',/dev
  232.         xyouts,lm,bm+75,'   Center Button Selects Size',/dev
  233.         xyouts,lm,bm+50,'   Right Button Exits',/dev
  234.  
  235.         wset,orig_w        ; Set to original image
  236.     endelse    
  237. endcase
  238.  
  239. goto,again                ; Return to original state
  240.  
  241. done:
  242.     if zoom_w ge 0 then wdelete,zoom_w    ; Done with windows
  243.     if pixel_w ge 0 then wdelete,pixel_w
  244.     b=0                ; Eliminate intermediate image
  245. end
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.